package com.techblogon.serviceexample;

import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONObject;

import com.techblogon.serviceexample.network.Main;
import com.techblogon.serviceexample.network.RestClient;

import android.R;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
public static Handler mUiHandler = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_item);	
		
		mUiHandler = new Handler() // Receive messages from service class 
        {
			public void handleMessage(Message msg)
        	{
          		switch(msg.what)
        		{
	          		case 0:
	          			// add the status which came from service and show on GUI
	          			Toast.makeText(MainActivity.this, msg.obj.toString(), Toast.LENGTH_LONG).show();
	          			break;
	          			         		
	        		default:
        			break;
        		}
        	}
        };
	}
	MediaPlayer player1;
	//start the service
	public void onClickStartServie(View V)
	{
		//start the service from here //MyService is your service class name
	//	startService(new Intent(this, MyService.class));
		AndroidBuildingMusicPlayerActivity vv=new AndroidBuildingMusicPlayerActivity();
		vv.playSong(0);
	//	  player1=MediaPlayer.create(this,R.raw.plik_mp3);
	//	  player1.start();
		
	}
	public void onClickDodajUzytkownika(View v){
		new MY1().start();
	}
	class MY1 extends Thread{
		public void run(){
			Main m=new Main();m.dodajuzytkownika("m", "h");
		}
	}
	//Stop the started service
	public void onClickStopService(View V)
	{
		//Stop the running service from here//MyService is your service class name
		//Service will only stop if it is already running.
		stopService(new Intent(this, MyService.class));
	}
	//send message to service
	public void onClickSendMessage (View v)
	{
		//only we need a handler to send message to any component.
		//here we will get the handler from the service first, then 
		//we will send a message to the service.

		if(null != MyService.mMyServiceHandler)
		{
			//first build the message and send.
			//put a integer value here and get it from the service handler
			//For Example: lets use 0 (msg.what = 0;) for getting service running status from the service
			Message msg = new Message();
			msg.what = 0; 
			msg.obj  = "Add your Extra Meaage Here"; // you can put extra message here
			MyService.mMyServiceHandler.sendMessage(msg);
		}
	}
	/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}*/

}
